Skip to content

@W-21474595 - add MCP tool-level response token usage (responseCharCount)#400

Open
smuduganti-sf wants to merge 3 commits intosalesforcecli:mainfrom
smuduganti-sf:W-20995739-add-responseCharCount
Open

@W-21474595 - add MCP tool-level response token usage (responseCharCount)#400
smuduganti-sf wants to merge 3 commits intosalesforcecli:mainfrom
smuduganti-sf:W-20995739-add-responseCharCount

Conversation

@smuduganti-sf
Copy link
Collaborator

@smuduganti-sf smuduganti-sf commented Mar 4, 2026

  • Added calculateResponseCharCount() to compute total character count from tool result content.
  • On each tool call, the response character count is computed and sent in the TOOL_CALLED telemetry event as responseCharCount.

What does this PR do?

@W-21474595@

What issues does this PR fix or reference?

@smuduganti-sf smuduganti-sf requested a review from a team as a code owner March 4, 2026 06:14
@smuduganti-sf smuduganti-sf changed the title @W-20995739 - add MCP tool-level response token usage (responseCharCount) @W-21474595 - add MCP tool-level response token usage (responseCharCount) Mar 6, 2026
@smuduganti-sf smuduganti-sf force-pushed the W-20995739-add-responseCharCount branch from 32cdc84 to 3b8b1ca Compare March 6, 2026 04:01
if (result.isError) this.logger.debug(`Tool ${name} errored`);

// Calculate response character count for token usage
const responseCharCount = this.calculateResponseCharCount(result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method only considers plain text from tool responses but tools can also have structured output, see:

Image

https://modelcontextprotocol.io/specification/2025-11-25/server/tools#output-schema

I think the safe way would be to account for both since a tool seems to be able to return plain text + structured output

@smuduganti-sf smuduganti-sf force-pushed the W-20995739-add-responseCharCount branch from 5b62886 to c75c061 Compare March 11, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants